<?php
############## DIT STUK CODE ZORGT ERVOOR DAT JE ALS ADMIN INGELOGD MOET ZIJN OM DE PAGINA TE KUNNEN ZIEN ##############
    //Start de sessie
    session_start();

    //Load de benodigde bestanden
    require_once("includes/auth.php");
########################################################################################################################
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Factuur bewerken</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link type="text/css" href="../css/pagination.css" rel="stylesheet" />
  <link rel="stylesheet" href="../css/reset.css" type="text/css" />
  <link rel="stylesheet" href="../css/960.css" type="text/css" />
  <link rel="stylesheet" href="../css/text.css" type="text/css" />
  <link type="text/css" href="../css/facttable.css" rel="stylesheet" />
  <link type="text/css" href="../css/sunny/jquery-ui-1.8.custom.css" rel="stylesheet" />
  <link type="text/css" href="../css/jquery.autocomplete.css" rel="stylesheet" />
  <link type="text/css" href="../css/style.css" rel="stylesheet" />
  <link type="text/css" href="../css/accmenu.css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery-1.4.2.min.js">
</script>
<script type="text/javascript" src="../js/jquery-ui-1.8.custom.min.js">
</script>
<script type="text/javascript" src="../js/jquery.tablesorter.js">
</script>
<script type="text/javascript" src="../js/jquery.autocomplete.min.js">
</script>
<script type="text/javascript" src="../js/menu.js">
</script>
</head>

<body>
  <div class="container_12">
    <div id="header" class="grid_12">

    </div>

    <div class="clear"></div>

    <div class="grid_12 spacer"></div>

    <div class="clear"></div>

    <div id="menu" class="grid_2">

        <?php
        include_once 'temp/menu_filler.php';
        ?>


    </div>

    <div id="adminarea" class="grid_10">
        <div id="tableholder">

              <?php

              // Connects to your Database
              include 'includes/connect.php';

              if (!isset($_POST['submit'])) // if page is not submitted to itself echo the form
              {
                  $fid=$_GET['fid'];

                      // Retrieve all the data from the table
                      $sql = "SELECT factuurregel.factuurid, factuurregel.productid, factuurregel.aantal, factuurregel.vkprijs, product.productnaam FROM factuurregel, product WHERE factuurregel.factuurid ='".$fid."' AND factuurregel.productid=product.productid  ";
                      // echo 'query is: ',$query;
                      $result = mysql_query($sql) or die("the query returned an error: " . mysql_error());

                      echo "<table class='facttable' border='1'>";
                      echo "<thead><tr> <th>Product ID</th> <th>Product Naam</th> <th>Aantal</th> <th>Verkoopsprijs</th> <th>Bevestigen</th> </tr></thead></table>";

                      while ($row = mysql_fetch_array($result)) {
                      $pid = $row['productid'];
                      $at = $row['aantal'];
                      $vp = $row['vkprijs'];
                      $pronaam = $row['productnaam'];?>

                      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
                      <table  class='facttable' border='1'><tbody><tr>
                      <input type= "hidden" name= "factuurid" value="<?php echo $fid ?>" />
                      <td><?php echo $pid ?><input type="hidden" name="productid" value="<?php echo $pid ?>" /></td>
                      <td><?php echo $pronaam ?> <input type="hidden" name="productnaam" value="<?php echo $pronaam ?>"/></td>
                      <td><input type="text" name="aantal" value="<?php echo $at ?>" /></td>
                      <td><input type="text" name="vkprijs" value="<?php echo $vp ?>" /></td>
                      <td><input type="submit" name="submit" value="submit"></td></tr></tbody>
                      </table></form>
                      <?php } ?>
                      <a href="manage_fact.php">Ga terug naar Bestellingsbeheer</a>



              <?php
              }
              else
              {
                  $sql="UPDATE factuurregel SET factuurid='$_POST[factuurid]',productid='$_POST[productid]',aantal='$_POST[aantal]',vkprijs='$_POST[vkprijs]' WHERE factuurid='$_POST[factuurid]' AND factuurregel.productid ='$_POST[productid]'";

                  if (!mysql_query($sql))
                    {
                    die('Error: ' . mysql_error());
                    }
                  echo "Factuurregel gewijzigd!<br />";
                  echo "<a href=\"edit_fact.php?fid=".$_POST['factuurid']."\">Ga terug naar factuur</a>";



              }

              ?>

        </div>
    </div>

    <div class="clear"></div>

    <div class="grid_12 spacer"></div>

    <div class="clear"></div>
</div>
</body>
</html>